package main;

/**
 * Citeste fisierul auxiliar
 */
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class ReadAuxFile {
	public BufferedReader br;
	public ArrayList<String> lines;
	public String [] splitLines=null;
	
	public ReadAuxFile(){
		try {
			br=new BufferedReader(new FileReader("auxiliar.txt"));
			lines=new ArrayList<String>();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * imparte scenariul in linii
	 */
	public void citire() throws IOException
	{
		String line;
		
		while((line=br.readLine())!=null)
		{
			lines.add(line);
		}
		br.close();
	}
	
	/**
	 * returneaza ora actiunii de la linia i
	 */
	public int getHour(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		for (int j=0; j<splitLines.length; j++)
			if (splitLines[j].contains(":"))
				{
					time=splitLines[j].split(":");
					return Integer.parseInt(time[0]);
				}
		return -1;
				
	}
	
	/**
	 * returneaza minutele de la actiunea din scenariul de la linia i
	 */
	public int getMinute(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		for (int j=0; j<splitLines.length; j++)
			if (splitLines[j].contains(":"))
				{
					time=splitLines[j].split(":");
					return Integer.parseInt(time[1]);
				}
		return -1;
	}
	
	/**
	 * returneaza secundele de la actiunea din scenariul de la linia i
	 */
	public int getSeconde(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		for (int j=0; j<splitLines.length; j++)
			if (splitLines[j].contains(":"))
				{
					time=splitLines[j].split(":");
					return Integer.parseInt(time[2]);
				}
		return -1;
	}
	
	/**
	 * in cazul in care avem al doilea complement de timp, returneaza ora de la acest complement
	 */
	public int getEndHours(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		time=splitLines[splitLines.length-1].split(":");
		return Integer.parseInt(time[0]);
				
	}
	
	/**
	 * in cazul in care avem al doilea complement de timp, returneaza minutele de la acest complement
	 */
	public int getEndMinutes(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		time=splitLines[splitLines.length-1].split(":");
		return Integer.parseInt(time[1]);
	}
	
	/**
	 * in cazul in care avem al doilea complement de timp, returneaza secundele de la acest complement
	 */
	public int getEndSeconds(int i)
	{
		String[] time;
		splitLines=lines.get(i).split(" ");
		time=splitLines[splitLines.length-1].split(":");
		return Integer.parseInt(time[2]);
	}
	
	/**
	 * returneaza actiunea de la linia i
	 */
	public String getAction(int i)
	{
		String[] actiune;
		actiune=lines.get(i).split(" ");
		return actiune[0];
	}
	/**
	 * returneaza atributul actiunii de la linia i
	 */
	public String getAttribute(int i)
	{
		String[] atribut;
		atribut=lines.get(i).split(" ");
		if (atribut[0].equalsIgnoreCase("merge_la_WC"))
			return atribut[2];
		if (atribut[0].equalsIgnoreCase("spala"))
			return atribut[2];
		if (atribut[0].equalsIgnoreCase("porneste")||atribut[0].equalsIgnoreCase("opreste")||atribut[0].equalsIgnoreCase("foloseste")||atribut[0].equalsIgnoreCase("seteaza"))
			if (atribut[2].equalsIgnoreCase("masina"))
				return atribut[2]+" "+atribut[3]+" "+atribut[4];
			else
				if (atribut[2].equalsIgnoreCase("aer"))
					return atribut[2]+" "+atribut[3];
				else
					return atribut[2];
		if (atribut[0].equalsIgnoreCase("merge"))
			return atribut[2];
		return null;
	}
	/**
	 * returneaza setarea actiunii de la linia i
	 */
	public String getSetting(int i)
	{
		String[] setare;
		setare=lines.get(i).split(" ");
		for (int k=0; k<setare.length; k++)
			if (setare[k].equalsIgnoreCase("intensitate") || setare[k].equalsIgnoreCase("putere"))
				return setare[k+1];
		return null;
	}
	/**
	 * returneaza numele locuitorului ce executa actiunea
	 */
	public String getPerson(int i)
	{
		String[] omulet;
		omulet=lines.get(i).split(" ");
		return omulet[1];
	}
}
